﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Text.RegularExpressions;
using System.Diagnostics;

namespace JJCraft
{
    class LogReader
    {
        private Regex mTimeParser;

        public LogReader()
        {
            mTimeParser = new Regex(@"^(\d+)/(\d+)\s+(\d+):(\d+):(\d+).(\d+)\s+");
        }

        public LogLine ReadLine(string line)
        {
            LogLine result = new LogLine()
            {
                Success = false
            };

            Match timeMatch = mTimeParser.Match(line);
            if (timeMatch.Success)
            {
                try
                {
                    int month = Convert.ToInt32(timeMatch.Groups[1].Value);
                    int day = Convert.ToInt32(timeMatch.Groups[2].Value);
                    int hour = Convert.ToInt32(timeMatch.Groups[3].Value);
                    int minute = Convert.ToInt32(timeMatch.Groups[4].Value);
                    int second = Convert.ToInt32(timeMatch.Groups[5].Value);
                    int ms = Convert.ToInt32(timeMatch.Groups[6].Value);

                    DateTime thisLineTime = new DateTime(DateTime.Now.Year, month, day, hour, minute, second, ms);
                    result.Time = thisLineTime;
                    result.Parameters = line.Substring(timeMatch.Length).Split(',');
                    result.Success = true;
                }
                catch (Exception ex)
                {
                    Debug.WriteLine("Log reading error: " + ex.Message);
                }
            }

            return result;
        }

        public LogLine ReadChatLine(string line)
        {
            LogLine result = new LogLine()
            {
                Success = false
            };

            Match timeMatch = mTimeParser.Match(line);
            if (timeMatch.Success)
            {
                try
                {
                    int month = Convert.ToInt32(timeMatch.Groups[1].Value);
                    int day = Convert.ToInt32(timeMatch.Groups[2].Value);
                    int hour = Convert.ToInt32(timeMatch.Groups[3].Value);
                    int minute = Convert.ToInt32(timeMatch.Groups[4].Value);
                    int second = Convert.ToInt32(timeMatch.Groups[5].Value);
                    int ms = Convert.ToInt32(timeMatch.Groups[6].Value);

                    DateTime thisLineTime = new DateTime(DateTime.Now.Year, month, day, hour, minute, second, ms);
                    result.Time = thisLineTime;
                    result.Parameters = new string[] { line.Substring(timeMatch.Length) };
                    result.Success = true;
                }
                catch (Exception ex)
                {
                    Debug.WriteLine("Log reading error: " + ex.Message);
                }
            }

            return result;
        }
    }

    enum LogItemType
    {
        Damage,
        Heal,
        Action
    }

    class LogLine
    {
        public bool Success { get; set; }
        public DateTime Time { get; set; }
        public string[] Parameters { get; set; }

        public string GetLongDescriptionText()
        {
            StringBuilder sb = new StringBuilder();
            sb.Append(Time.ToString());
            sb.Append(" ");

            long srcGUID = long.Parse(Parameters[1].Substring(2), System.Globalization.NumberStyles.HexNumber);
            string srcName = Combat.GetName(Parameters[2]);
            long srcFlag = long.Parse(Parameters[3].Substring(2), System.Globalization.NumberStyles.HexNumber);

            long destGUID = long.Parse(Parameters[4].Substring(2), System.Globalization.NumberStyles.HexNumber);
            string destName = Combat.GetName(Parameters[5]);
            long destFlag = long.Parse(Parameters[6].Substring(2), System.Globalization.NumberStyles.HexNumber);

            switch (Parameters[0])
            {
                default:
                case "SWING_MISSED":
                    {
                        string missType = GetMissTypeString(Parameters[7]);
                        if (missType == "吸收" || missType == "抵抗" && Parameters.Length >= 9)
                        {
                            sb.Append(String.Format("{0} 对 {1} 的 平砍 被{2}了. 原可造成{3}点伤害.", srcName, destName, missType, Parameters[8]));
                        }
                        else
                        {
                            sb.Append(String.Format("{0} 对 {1} 的 平砍 被{2}了.", srcName, destName, missType));
                        }
                    }
                    break;
                case "RANGE_MISSED":
                case "SPELL_MISSED":
                case "SPELL_PERIODIC_MISSED":
                case "DAMAGE_SHIELD_MISSED":
                    {
                        string spellName = Combat.GetName(Parameters[8]);
                        string missType = GetMissTypeString(Parameters[10]);

                        if (missType == "吸收" || missType == "抵抗" && Parameters.Length >= 12)
                        {
                            sb.Append(String.Format("{0} 对 {1} 的 {2} 被{3}了. 原可造成{4}点伤害.", srcName, destName, spellName, missType, Parameters[11]));
                        }
                        else
                        {
                            sb.Append(String.Format("{0} 对 {1} 的 {2} 被{3}了.", srcName, destName, spellName, missType));
                        }
                    }
                    break;
                case "SPELL_CAST_SUCCESS":
                    {
                        string spellName = Combat.GetName(Parameters[8]);
                        if (destName != "nil")
                        {
                            sb.Append(String.Format("{0} 成功地对 {1} 施放了 {2}.", srcName, destName, spellName));
                        }
                        else
                        {
                            sb.Append(String.Format("{0} 成功地施放了 {1}.", srcName, spellName));
                        }
                    }
                    break;
                case "SPELL_AURA_APPLIED":
                    {
                        string spellName = Combat.GetName(Parameters[8]);

                        sb.Append(String.Format("{1} 受到了 {0} 的 {2} 效果影响.", srcName, destName, spellName));
                    }
                    break;
                case "SPELL_AURA_REMOVED":
                    {
                        string spellName = Combat.GetName(Parameters[8]);

                        sb.Append(String.Format("{0} 对 {1} 施放的 {2} 效果消失了.", srcName, destName, spellName));
                    }
                    break;
                case "SPELL_STOLEN":
                    {
                        string spellName = Combat.GetName(Parameters[8]);
                        string stolen = Combat.GetName(Parameters[11]);

                        sb.Append(String.Format("{0} 施展 {2} 并偷取了 {1} 的 {3} 效果.", srcName, destName, spellName, stolen));
                    }
                    break;
                case "SPELL_INTERRUPT":
                    {
                        string spellName = Combat.GetName(Parameters[8]);
                        string inter = Combat.GetName(Parameters[11]);

                        sb.Append(String.Format("{0} 用 {2} 打断了 {1} 的 {3}.", srcName, destName, spellName, inter));
                    }
                    break;
                case "SPELL_DISPEL":
                    {
                        string spellName = Combat.GetName(Parameters[8]);
                        string dispel = Combat.GetName(Parameters[11]);

                        sb.Append(String.Format("{0} 用 {2} 移除了 {1} 的 {3} 效果.", srcName, destName, spellName, dispel));
                    }
                    break;
                case "SPELL_DISPEL_FAILED":
                    {
                        string spellName = Combat.GetName(Parameters[8]);
                        string dispel = Combat.GetName(Parameters[11]);

                        sb.Append(String.Format("{0} 未能成功地用 {2} 移除 {1} 的 {3} 效果.", srcName, destName, spellName, dispel));
                    }
                    break;
                case "SPELL_EXTRA_ATTACKS":
                    {
                        string spellName = Combat.GetName(Parameters[8]);
                        string extraCount = Parameters[10];

                        sb.Append(String.Format("{1} 因为 {0} 的 {2} 而获得了{3}次额外攻击.", srcName, destName, spellName, extraCount));
                    }
                    break;
                case "SPELL_AURA_APPLIED_DOSE":
                    {
                        string spellName = Combat.GetName(Parameters[8]);
                        string dose = Parameters[11];

                        sb.Append(String.Format("{0} 对 {1} 施加的 {2} 叠加到了{3}层.", srcName, destName, spellName, dose));
                    }
                    break;
                case "SPELL_AURA_REMOVED_DOSE":
                    {
                        string spellName = Combat.GetName(Parameters[8]);
                        string dose = Parameters[11];

                        sb.Append(String.Format("{0} 对 {1} 施加的 {2} 还剩{3}层.", srcName, destName, spellName, dose));
                    }
                    break;
                case "SPELL_AURA_REFRESH":
                    {
                        string spellName = Combat.GetName(Parameters[8]);

                        sb.Append(String.Format("{0} 刷新了对 {1} 施加的 {2} 效果.", srcName, destName, spellName));
                    }
                    break;
                case "SPELL_AURA_BROKEN":
                    {
                        string spellName = Combat.GetName(Parameters[8]);

                        sb.Append(String.Format("{0} 的 平砍 打破了 {1} 身上的 {2} 效果.", srcName, destName, spellName));
                    }
                    break;
                case "SPELL_AURA_BROKEN_SPELL":
                    {
                        string spellName = Combat.GetName(Parameters[8]);
                        string breaker = Combat.GetName(Parameters[11]);

                        sb.Append(String.Format("{0} 的 {3} 打破了 {1} 身上的 {2} 效果.", srcName, destName, spellName, breaker));
                    }
                    break;
                case "SWING_DAMAGE":
                    {
                        string amount = Parameters[7];
                        int resisted = Convert.ToInt32(Parameters[10]);
                        int blocked = Convert.ToInt32(Parameters[11]);
                        int absorbed = Convert.ToInt32(Parameters[12]);
                        string critical = Parameters[13];
                        string glancing = Parameters[14];

                        if (critical == "1")
                        {
                            critical = "暴击";
                        }
                        else
                        {
                            critical = string.Empty;
                        }

                        if (glancing == "1")
                        {
                            glancing = "(偏斜)";
                        }
                        else
                        {
                            glancing = string.Empty;
                        }

                        sb.Append(String.Format("{0} 对 {1} 的 平砍{2} 造成 {3} 点伤害. ", srcName, destName, critical, amount));
                        if (resisted > 0)
                        {
                            sb.Append(String.Format("{0}点被抵抗. ", resisted));
                        }
                        if (blocked > 0)
                        {
                            sb.Append(String.Format("{0}点被格挡. ", blocked));
                        }
                        if (absorbed > 0)
                        {
                            sb.Append(String.Format("{0}点被吸收. ", absorbed));
                        }
                        sb.Append(glancing);
                    }
                    break;
                case "ENVIRONMENTAL_DAMAGE":
                    {
                        string type = Parameters[7];
                        string amount = Parameters[8];
                        int resisted = Convert.ToInt32(Parameters[11]);
                        int blocked = Convert.ToInt32(Parameters[12]);
                        int absorbed = Convert.ToInt32(Parameters[13]);
                        string critical = Parameters[14];
                        string glancing = Parameters[15];

                        if (critical == "1")
                        {
                            critical = "暴击";
                        }
                        else
                        {
                            critical = string.Empty;
                        }

                        if (glancing == "1")
                        {
                            glancing = "(偏斜)";
                        }
                        else
                        {
                            glancing = string.Empty;
                        }

                        sb.Append(String.Format("{0}({4}{2}) 对 {1} 造成 {3} 点伤害. ", "环境", destName, critical, amount, type));
                        if (resisted > 0)
                        {
                            sb.Append(String.Format("{0}点被抵抗. ", resisted));
                        }
                        if (blocked > 0)
                        {
                            sb.Append(String.Format("{0}点被格挡. ", blocked));
                        }
                        if (absorbed > 0)
                        {
                            sb.Append(String.Format("{0}点被吸收. ", absorbed));
                        }
                        sb.Append(glancing);
                    }
                    break;
                case "RANGE_DAMAGE":
                case "SPELL_DAMAGE":
                case "SPELL_PERIODIC_DAMAGE":
                case "DAMAGE_SHIELD":
                    {
                        string spellName = Combat.GetName(Parameters[8]);
                        string amount = Parameters[10];
                        int resisted = Convert.ToInt32(Parameters[13]);
                        int blocked = Convert.ToInt32(Parameters[14]);
                        int absorbed = Convert.ToInt32(Parameters[15]);
                        string critical = Parameters[16];
                        string glancing = Parameters[17];

                        if (critical == "1")
                        {
                            critical = "暴击";
                        }
                        else
                        {
                            critical = string.Empty;
                        }

                        if (glancing == "1")
                        {
                            glancing = "(偏斜)";
                        }
                        else
                        {
                            glancing = string.Empty;
                        }

                        sb.Append(String.Format("{0} 的 {4}{2} 对 {1} 造成 {3} 点伤害. ", srcName, destName, critical, amount, spellName));
                        if (resisted > 0)
                        {
                            sb.Append(String.Format("{0}点被抵抗. ", resisted));
                        }
                        if (blocked > 0)
                        {
                            sb.Append(String.Format("{0}点被格挡. ", blocked));
                        }
                        if (absorbed > 0)
                        {
                            sb.Append(String.Format("{0}点被吸收. ", absorbed));
                        }
                        sb.Append(glancing);
                    }
                    break;
                case "SPELL_DRAIN":
                case "SPELL_PERIODIC_DRAIN":
                    {
                        string spellName = Combat.GetName(Parameters[8]);
                        string amount = Parameters[10];
                        string powerType = GetPowerTypeString(Parameters[11]);

                        sb.Append(String.Format("{0} 的 {2} 使 {1} 流失了{3}点{4}.", srcName, destName, spellName, amount, powerType));
                    }
                    break;
                case "SPELL_LEECH":
                case "SPELL_PERIODIC_LEECH":
                    {
                        string spellName = Combat.GetName(Parameters[8]);
                        string amount = Parameters[10];
                        string powerType = GetPowerTypeString(Parameters[11]);
                        string extraAmount = Parameters[12];

                        sb.Append(String.Format("{0} 的 {2} 使 {1} 流失了{3}点{4}, 并使 {0} 获得了{5}点{4}.", srcName, destName, spellName, amount, powerType, extraAmount));
                    }
                    break;
                case "SPELL_HEAL":
                case "SPELL_PERIODIC_HEAL":
                    {
                        string spellName = Combat.GetName(Parameters[8]);
                        int amount = Convert.ToInt32(Parameters[10]);
                        int overheal = Convert.ToInt32(Parameters[11]);
                        string critical = Parameters[12];

                        amount -= overheal;

                        if (critical == "1")
                        {
                            critical = "暴击";
                        }
                        else
                        {
                            critical = string.Empty;
                        }

                        sb.Append(String.Format("{0} 的 {2}{3} 为 {1} 治疗了{4}点生命. ", srcName, destName, spellName, critical, amount));
                        if (overheal > 0)
                        {
                            sb.Append(String.Format("另有{0}点过量治疗. ", overheal));
                        }
                    }
                    break;
                case "SPELL_PERIODIC_ENERGIZE":
                case "SPELL_ENERGIZE":
                    {
                        string spellName = Combat.GetName(Parameters[8]);
                        string amount = Parameters[10];
                        string powerType = GetPowerTypeString(Parameters[11]);

                        sb.Append(String.Format("{0} 的 {2} 使 {1} 恢复了{3}点{4}. ", srcName, destName, spellName, amount, powerType));
                    }
                    break;
                case "DAMAGE_SPLIT":
                    {
                        string spellName = Combat.GetName(Parameters[8]);
                        string amount = Parameters[10];

                        sb.Append(String.Format("{1} 由于 {2} 而为 {0} 分担了{3}点伤害.", srcName, destName, spellName, amount));
                    }
                    break;
                case "UNIT_DIED":
                    {
                        sb.Append(String.Format("{0} 死了.", destName));
                    }
                    break;
            }

            return sb.ToString();
        }

        public string GetShortDescriptionText()
        {
            switch (Parameters[0])
            {
                default:
                case "SWING_MISSED":
                    {
                        string missType = GetMissTypeString(Parameters[7]);
                        return String.Format("平砍({0})", missType);
                    }
                case "RANGE_MISSED":
                case "SPELL_MISSED":
                case "SPELL_PERIODIC_MISSED":
                case "DAMAGE_SHIELD_MISSED":
                    {
                        string spellName = Combat.GetName(Parameters[8]);
                        string missType = GetMissTypeString(Parameters[10]);
                        return String.Format("{0}({1})", spellName, missType);
                    }
                case "SPELL_CAST_SUCCESS":
                    {
                        string spellName = Combat.GetName(Parameters[8]);
                        return String.Format("施放:{0}", spellName);
                    }
                case "SPELL_AURA_APPLIED":
                    {
                        string spellName = Combat.GetName(Parameters[8]);
                        return String.Format("{0}+", spellName);
                    }
                case "SPELL_AURA_REMOVED":
                    {
                        string spellName = Combat.GetName(Parameters[8]);
                        return String.Format("{0}-", spellName);
                    }
                case "SPELL_STOLEN":
                    {
                        string stolen = Combat.GetName(Parameters[11]);
                        return String.Format("偷取:{0}", stolen);
                    }
                case "SPELL_INTERRUPT":
                    {
                        string inter = Combat.GetName(Parameters[11]);
                        return String.Format("打断:{0}", inter);
                    }
                case "SPELL_DISPEL":
                    {
                        string dispel = Combat.GetName(Parameters[11]);
                        return String.Format("移除:{0}", dispel);
                    }
                case "SPELL_DISPEL_FAILED":
                    {
                        string dispel = Combat.GetName(Parameters[11]);
                        return String.Format("移除失败:{0}", dispel);
                    }
                case "SPELL_EXTRA_ATTACKS":
                    {
                        return "额外攻击";
                    }
                case "SPELL_AURA_APPLIED_DOSE":
                    {
                        string spellName = Combat.GetName(Parameters[8]);
                        string dose = Parameters[11];
                        return String.Format("{0}*{1}", spellName, dose);
                    }
                case "SPELL_AURA_REMOVED_DOSE":
                    {
                        string spellName = Combat.GetName(Parameters[8]);
                        string dose = Parameters[11];
                        return String.Format("{0}*{1}", spellName, dose);
                    }
                case "SPELL_AURA_REFRESH":
                    {
                        string spellName = Combat.GetName(Parameters[8]);
                        return String.Format("刷新:{0}", spellName);
                    }
                case "SPELL_AURA_BROKEN":
                    {
                        string spellName = Combat.GetName(Parameters[8]);
                        return String.Format("打破:{0}", spellName);
                    }
                case "SPELL_AURA_BROKEN_SPELL":
                    {
                        string spellName = Combat.GetName(Parameters[8]);
                        return String.Format("打破:{0}", spellName);
                    }
                case "SWING_DAMAGE":
                    {
                        string amount = Parameters[7];
                        return String.Format("平砍:{0}", amount);
                    }
                case "ENVIRONMENTAL_DAMAGE":
                    {
                        string type = Parameters[7];
                        string amount = Parameters[8];
                        return String.Format("环境{0}:{1}", type, amount);
                    }
                case "RANGE_DAMAGE":
                case "SPELL_DAMAGE":
                case "SPELL_PERIODIC_DAMAGE":
                case "DAMAGE_SHIELD":
                case "SPELL_DRAIN":
                case "SPELL_LEECH":
                case "SPELL_PERIODIC_DRAIN":
                case "SPELL_PERIODIC_LEECH":
                case "SPELL_PERIODIC_ENERGIZE":
                case "SPELL_ENERGIZE":
                    {
                        string spellName = Combat.GetName(Parameters[8]);
                        string amount = Parameters[10];
                        return String.Format("{0}:{1}", spellName, amount);
                    }
                case "DAMAGE_SPLIT":
                    {
                        string spellName = Combat.GetName(Parameters[8]);
                        string amount = Parameters[10];
                        return String.Format("{0}分担:{1}", spellName, amount);
                    }
                case "UNIT_DIED":
                    {
                        return "死亡";
                    }
                case "SPELL_HEAL":
                case "SPELL_PERIODIC_HEAL":
                    {
                        string spellName = Combat.GetName(Parameters[8]);
                        int amount = Convert.ToInt32(Parameters[10]);
                        int overheal = Convert.ToInt32(Parameters[11]);

                        amount -= overheal;

                        return String.Format("{0}:{1}", spellName, amount);
                    }
            }
        }

        private string GetPowerTypeString(string powerType)
        {
            switch (powerType)
            {
                case "-2":
                    return "生命";
                case "0":
                    return "法力";
                case "1":
                    return "怒气";
                case "2":
                    return "集中值";
                case "3":
                    return "能量";
                case "4":
                    return "宠物快乐度";
                case "5":
                    return "符文";
                case "6":
                    return "符文能量";
                default:
                    return "能量";
            }
        }

        private string GetMissTypeString(string missType)
        {
            switch (missType)
            {
                case "DODGE":
                    return "躲闪";
                case "BLOCK":
                    return "格挡";
                case "IMMUNE":
                    return "免疫";
                case "RESIST":
                    return "抵抗";
                case "MISS":
                    return "未命中";
                case "ABSORB":
                    return "吸收";
                case "PARRY":
                    return "招架";
                case "REFLECT":
                    return "反射";
                case "DEFLECT":
                    return "偏斜";
                default:
                    return missType;
            }
        }

        public UnitClass GetClassForIn(Combat combat)
        {
            long srcGUID = long.Parse(Parameters[1].Substring(2), System.Globalization.NumberStyles.HexNumber);
            long destGUID = long.Parse(Parameters[4].Substring(2), System.Globalization.NumberStyles.HexNumber);

            UnitClass srcClass = combat.Units[srcGUID].Class;
            UnitClass destClass = combat.Units[destGUID].Class;

            switch (Parameters[0])
            {
                default:
                case "SWING_MISSED":
                case "RANGE_MISSED":
                case "SPELL_MISSED":
                case "SPELL_PERIODIC_MISSED":
                case "DAMAGE_SHIELD_MISSED":
                case "SPELL_CAST_SUCCESS":
                case "SPELL_AURA_APPLIED":
                case "SPELL_AURA_REMOVED":
                case "SPELL_STOLEN":
                case "SPELL_INTERRUPT":
                case "SPELL_DISPEL":
                case "SPELL_DISPEL_FAILED":
                case "SPELL_EXTRA_ATTACKS":
                case "SPELL_AURA_APPLIED_DOSE":
                case "SPELL_AURA_REMOVED_DOSE":
                case "SPELL_AURA_REFRESH":
                case "SPELL_AURA_BROKEN":
                case "SPELL_AURA_BROKEN_SPELL":
                case "SWING_DAMAGE":
                case "ENVIRONMENTAL_DAMAGE":
                case "RANGE_DAMAGE":
                case "SPELL_DAMAGE":
                case "SPELL_PERIODIC_DAMAGE":
                case "DAMAGE_SHIELD":
                case "DAMAGE_SPLIT":
                case "SPELL_DRAIN":
                case "SPELL_LEECH":
                case "SPELL_PERIODIC_DRAIN":
                case "SPELL_PERIODIC_LEECH":
                case "SPELL_HEAL":
                case "SPELL_PERIODIC_HEAL":
                case "SPELL_PERIODIC_ENERGIZE":
                case "SPELL_ENERGIZE":
                case "UNIT_DIED":
                    return srcClass;
            }
        }

        public UnitClass GetClassForOut(Combat combat)
        {
            long srcGUID = long.Parse(Parameters[1].Substring(2), System.Globalization.NumberStyles.HexNumber);
            long destGUID = long.Parse(Parameters[4].Substring(2), System.Globalization.NumberStyles.HexNumber);

            UnitClass srcClass = combat.Units[srcGUID].Class;
            UnitClass destClass = combat.Units[destGUID].Class;

            switch (Parameters[0])
            {
                default:
                case "SWING_MISSED":
                case "RANGE_MISSED":
                case "SPELL_MISSED":
                case "SPELL_PERIODIC_MISSED":
                case "DAMAGE_SHIELD_MISSED":
                case "SPELL_CAST_SUCCESS":
                case "SPELL_AURA_APPLIED":
                case "SPELL_AURA_REMOVED":
                case "SPELL_STOLEN":
                case "SPELL_INTERRUPT":
                case "SPELL_DISPEL":
                case "SPELL_DISPEL_FAILED":
                case "SPELL_EXTRA_ATTACKS":
                case "SPELL_AURA_APPLIED_DOSE":
                case "SPELL_AURA_REMOVED_DOSE":
                case "SPELL_AURA_REFRESH":
                case "SPELL_AURA_BROKEN":
                case "SPELL_AURA_BROKEN_SPELL":
                case "SWING_DAMAGE":
                case "ENVIRONMENTAL_DAMAGE":
                case "RANGE_DAMAGE":
                case "SPELL_DAMAGE":
                case "SPELL_PERIODIC_DAMAGE":
                case "DAMAGE_SHIELD":
                case "DAMAGE_SPLIT":
                case "SPELL_DRAIN":
                case "SPELL_LEECH":
                case "SPELL_PERIODIC_DRAIN":
                case "SPELL_PERIODIC_LEECH":
                case "SPELL_HEAL":
                case "SPELL_PERIODIC_HEAL":
                case "SPELL_PERIODIC_ENERGIZE":
                case "SPELL_ENERGIZE":
                case "UNIT_DIED":
                    return destClass;
            }
        }

        public string GetWidthForEventItem()
        {
            string defaultWidth = "";
            int numericMinWidth = 100;
            int numericMinValue = 1000;
            int numericMaxWidth = 500;
            int numericMaxValue = 6000;

            switch (Parameters[0])
            {
                default:
                case "SWING_MISSED":
                case "RANGE_MISSED":
                case "SPELL_MISSED":
                case "SPELL_PERIODIC_MISSED":
                case "DAMAGE_SHIELD_MISSED":
                case "SPELL_CAST_SUCCESS":
                case "SPELL_AURA_APPLIED":
                case "SPELL_AURA_REMOVED":
                case "SPELL_INTERRUPT":
                case "SPELL_STOLEN":
                case "SPELL_DISPEL":
                case "SPELL_DISPEL_FAILED":
                case "SPELL_EXTRA_ATTACKS":
                case "SPELL_AURA_APPLIED_DOSE":
                case "SPELL_AURA_REMOVED_DOSE":
                case "SPELL_AURA_REFRESH":
                case "SPELL_AURA_BROKEN":
                case "SPELL_AURA_BROKEN_SPELL":
                    return defaultWidth;
                case "SWING_DAMAGE":
                    {
                        int damage = Convert.ToInt32(Parameters[7]);

                        if (damage < numericMinValue)
                        {
                            return defaultWidth;
                        }

                        if (damage > numericMaxValue)
                        {
                            damage = numericMaxValue;
                        }
                        return String.Format("width: {0}px;", (int)(numericMinWidth + (numericMaxWidth - numericMinWidth) * (double)damage / (double)numericMaxValue));
                    }
                case "ENVIRONMENTAL_DAMAGE":
                    {
                        int damage = Convert.ToInt32(Parameters[8]);

                        if (damage < numericMinValue)
                        {
                            return defaultWidth;
                        }

                        if (damage > numericMaxValue)
                        {
                            damage = numericMaxValue;
                        }
                        return String.Format("width: {0}px;", (int)(numericMinWidth + (numericMaxWidth - numericMinWidth) * (double)damage / (double)numericMaxValue));
                    }
                case "RANGE_DAMAGE":
                case "SPELL_DAMAGE":
                case "SPELL_PERIODIC_DAMAGE":
                case "DAMAGE_SHIELD":
                case "DAMAGE_SPLIT":
                case "SPELL_PERIODIC_ENERGIZE":
                case "SPELL_ENERGIZE":
                case "SPELL_DRAIN":
                case "SPELL_LEECH":
                case "SPELL_PERIODIC_DRAIN":
                case "SPELL_PERIODIC_LEECH":
                    {
                        int damage = Convert.ToInt32(Parameters[10]);

                        if (damage < numericMinValue)
                        {
                            return defaultWidth;
                        }

                        if (damage > numericMaxValue)
                        {
                            damage = numericMaxValue;
                        }
                        return String.Format("width: {0}px;", (int)(numericMinWidth + (numericMaxWidth - numericMinWidth) * (double)damage / (double)numericMaxValue));
                    }
                case "SPELL_HEAL":
                case "SPELL_PERIODIC_HEAL":
                    {
                        int damage = Convert.ToInt32(Parameters[10]);
                        int overheal = Convert.ToInt32(Parameters[11]);

                        damage -= overheal;

                        if (damage < numericMinValue)
                        {
                            return defaultWidth;
                        }

                        if (damage > numericMaxValue)
                        {
                            damage = numericMaxValue;
                        }
                        return String.Format("width: {0}px;", (int)(numericMinWidth + (numericMaxWidth - numericMinWidth) * (double)damage / (double)numericMaxValue));
                    }
            }
        }

        public LogItemType GetItemType()
        {
            switch (Parameters[0])
            {
                default:
                case "SWING_MISSED":
                case "RANGE_MISSED":
                case "SPELL_MISSED":
                case "SPELL_PERIODIC_MISSED":
                case "DAMAGE_SHIELD_MISSED":
                case "SPELL_CAST_SUCCESS":
                case "SPELL_AURA_APPLIED":
                case "SPELL_AURA_REMOVED":
                case "SPELL_INTERRUPT":
                case "SPELL_STOLEN":
                case "SPELL_DISPEL":
                case "SPELL_DISPEL_FAILED":
                case "SPELL_EXTRA_ATTACKS":
                case "SPELL_AURA_APPLIED_DOSE":
                case "SPELL_AURA_REMOVED_DOSE":
                case "SPELL_AURA_REFRESH":
                case "SPELL_AURA_BROKEN":
                case "SPELL_AURA_BROKEN_SPELL":
                case "SPELL_ENERGIZE":
                case "SPELL_PERIODIC_ENERGIZE":
                    return LogItemType.Action;
                case "SWING_DAMAGE":
                case "ENVIRONMENTAL_DAMAGE":
                case "RANGE_DAMAGE":
                case "SPELL_DAMAGE":
                case "SPELL_PERIODIC_DAMAGE":
                case "DAMAGE_SHIELD":
                case "DAMAGE_SPLIT":
                case "SPELL_DRAIN":
                case "SPELL_LEECH":
                case "SPELL_PERIODIC_DRAIN":
                case "SPELL_PERIODIC_LEECH":
                    return LogItemType.Damage;
                case "SPELL_HEAL":
                case "SPELL_PERIODIC_HEAL":
                    return LogItemType.Heal;
            }
        }
    }
}
